<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="85px">
      <el-form-item label="名称" prop="parkingLotCode" v-hasPermi="['parking:recordIn:edit']">
        <el-select v-model="queryParams.parkingLotCode" placeholder="请选择停车场" clearable>
          <el-option
            v-for="dict in parkingInfoList"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="车主类型" prop="ownerType">
        <el-select v-model="queryParams.ownerType" placeholder="请选择车主类型" clearable>
          <el-option
            v-for="dict in dict.type.owner_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="车牌号码" prop="carNum">
        <el-input
          v-model="queryParams.carNum"
          placeholder="请输入车牌号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆入场时间" label-width="110px">
        <el-date-picker
          v-model="daterangeCarInTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          :disabled="true"-->
<!--          v-hasPermi="['parking:recordIn:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['parking:recordIn:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['parking:recordIn:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['parking:recordIn:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table max-height="500" v-loading="loading" :data="recordInList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="主键ID" align="center" prop="id" width="80"/>-->
      <el-table-column label="停车场名称" align="center" prop="parkingLotName" />
      <el-table-column label="车牌号码" align="center" prop="carNum" />
      <el-table-column label="车主类型" align="center" prop="ownerType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.owner_type" :value="scope.row.ownerType"/>
        </template>
      </el-table-column>
      <el-table-column label="车牌颜色" align="center" prop="carNumColor" width="80">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.car_num_color" :value="scope.row.carNumColor"/>
        </template>
      </el-table-column>
      <el-table-column label="车辆颜色" align="center" prop="carColor" width="80">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.car_color" :value="scope.row.carColor"/>
        </template>
      </el-table-column>
      <el-table-column label="车辆状态" align="center" prop="carStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.car_status" :value="scope.row.carStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="车辆类型" align="center" prop="carType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.car_type" :value="scope.row.carType"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="设备通道编码" align="center" prop="enterItcDevChnCode" />-->
      <el-table-column label="设备通道名称" align="center" prop="enterItcDevChnName" />
      <el-table-column label="入场时间" align="center" prop="carInTime" width="200"/>
<!--      <el-table-column label="车道编码" align="center" prop="enterLaneCode" />-->
      <el-table-column label="监控类型" align="center" prop="monitorType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.monitor_type" :value="scope.row.monitorType"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
<!--          <el-button
            size="mini"
            type="text"
            icon="el-icon-guide"
            @click="handleOpenGate(scope.row)"
          >远程开闸</el-button>-->
<!--          <el-button-->
<!--            type="text"-->
<!--            size="small"-->
<!--            icon="el-icon-view"-->
<!--            @click="handlePreview(scope.row)"-->
<!--          >查看</el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['parking:recordIn:edit']"
          >记录矫正</el-button>
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['parking:recordIn:remove']"-->
<!--          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改车辆进场记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
<!--        <el-form-item label="平台ID" prop="platformId">-->
<!--          <el-input v-model="form.platformId" placeholder="请输入平台ID" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="唯一ID" prop="uniqueId">-->
<!--          <el-input v-model="form.uniqueId" placeholder="请输入唯一ID" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="抓拍序列号" prop="captureSeq">-->
<!--          <el-input v-model="form.captureSeq" placeholder="请输入抓拍序列号" />-->
<!--        </el-form-item>-->
        <el-form-item label="记录ID" prop="recordId">
<!--          <el-input v-model="form.recordId" placeholder="请输入记录ID" readonly />-->
          <span>{{ form.recordId}}</span>
        </el-form-item>
        <el-form-item label="停车场编码" prop="parkingLotCode">
<!--          <el-input v-model="form.parkingLotCode" placeholder="请输入停车场编码" readonly />-->
          <span>{{ form.parkingLotCode}}</span>
        </el-form-item>
        <el-form-item label="停车场名称" prop="parkingLotName">
<!--          <el-input v-model="form.parkingLotName" placeholder="请输入停车场名称" readonly />-->
          <span>{{ form.parkingLotName}}</span>
        </el-form-item>
        <el-form-item label="车主姓名" prop="ownerName">
          <el-input v-model="form.ownerName" placeholder="请输入车主姓名" />
        </el-form-item>
        <el-form-item label="车主电话" prop="ownerPhone">
          <el-input v-model="form.ownerPhone" placeholder="请输入车主电话" />
        </el-form-item>
<!--        <el-form-item label="车主类型" prop="ownerType">-->
<!--          <el-select v-model="form.ownerType" placeholder="请选择车主类型">-->
<!--            <el-option-->
<!--              v-for="dict in dict.type.owner_type"-->
<!--              :key="dict.value"-->
<!--              :label="dict.label"-->
<!--              :value="parseInt(dict.value)"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
        <el-form-item label="车牌颜色" prop="carNumColor">
          <el-select v-model="form.carNumColor" placeholder="请选择车牌颜色">
            <el-option
              v-for="dict in dict.type.car_num_color"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="车辆颜色" prop="carColor">
          <el-select v-model="form.carColor" placeholder="请选择车辆颜色">
            <el-option
              v-for="dict in dict.type.car_color"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="车牌号码" prop="carNum">
          <el-input v-model="form.carNum" placeholder="请输入车牌号码" />
        </el-form-item>
<!--        <el-form-item label="车辆状态" prop="carStatus">-->
<!--          <el-select v-model="form.carStatus" placeholder="请选择车辆状态">-->
<!--            <el-option-->
<!--              v-for="dict in dict.type.car_status"-->
<!--              :key="dict.value"-->
<!--              :label="dict.label"-->
<!--              :value="parseInt(dict.value)"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="车辆类型" prop="carType">-->
<!--          <el-select v-model="form.carType" placeholder="请选择车辆类型">-->
<!--            <el-option-->
<!--              v-for="dict in dict.type.car_type"-->
<!--              :key="dict.value"-->
<!--              :label="dict.label"-->
<!--              :value="parseInt(dict.value)"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="入口设备通道编码" prop="enterItcDevChnCode">-->
<!--          <el-input v-model="form.enterItcDevChnCode" placeholder="请输入入口设备通道编码" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="入口设备通道名称" prop="enterItcDevChnName">-->
<!--          <el-input v-model="form.enterItcDevChnName" placeholder="请输入入口设备通道名称" />-->
<!--        </el-form-item>-->
        <el-form-item label="车辆入场时间" prop="carInTime">
          <el-date-picker clearable
            v-model="form.carInTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择车辆入场时间">
          </el-date-picker>
        </el-form-item>
<!--        <el-form-item label="入口车道编码" prop="enterLaneCode">-->
<!--          <el-input v-model="form.enterLaneCode" placeholder="请输入入口车道编码" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="图片路径" prop="picPath">-->
<!--          <el-input v-model="form.picPath" placeholder="请输入图片路径" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="图片预览">-->
<!--          <img :src="form.picData" alt="图片预览" style="max-width: 100%; max-height: 200px;" v-if="form.picData" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="监控类型" prop="monitorType">-->
<!--          <el-select v-model="form.monitorType" placeholder="请选择监控类型">-->
<!--            <el-option-->
<!--              v-for="dict in dict.type.monitor_type"-->
<!--              :key="dict.value"-->
<!--              :label="dict.label"-->
<!--              :value="parseInt(dict.value)"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer" v-hasPermi="['parking:recordIn:list']">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRecordIn, getRecordIn, delRecordIn, addRecordIn, updateRecordIn, openGate } from "@/api/parking/recordIn";
import { selectParkingInfoList } from "@/api/parking/selectList";

export default {
  name: "RecordIn",
  dicts: ['monitor_type', 'owner_type', 'car_color', 'car_status', 'car_num_color', 'car_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 车辆进场记录表格数据
      recordInList: [],
      parkingInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 监控类型时间范围
      daterangeCarInTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        parkingLotName: null,
        ownerType: null,
        carNumColor: null,
        carColor: null,
        carNum: null,
        carStatus: null,
        carType: null,
        carInTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        uniqueId: [
          { required: true, message: "唯一ID不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getParkingInfoList();
  },
  methods: {
    /** 查询车辆进场记录列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCarInTime && '' != this.daterangeCarInTime) {
        this.queryParams.params["beginCarInTime"] = this.daterangeCarInTime[0];
        this.queryParams.params["endCarInTime"] = this.daterangeCarInTime[1];
      }
      listRecordIn(this.queryParams).then(response => {
        this.recordInList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getParkingInfoList() {
      selectParkingInfoList().then(response => {
        this.parkingInfoList = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        platformId: null,
        uniqueId: null,
        captureSeq: null,
        recordId: null,
        parkingLotCode: null,
        parkingLotName: null,
        ownerName: null,
        ownerPhone: null,
        ownerType: null,
        carNumColor: null,
        carColor: null,
        carListType: null,
        carNum: null,
        carStatus: null,
        carType: null,
        enterItcDevChnCode: null,
        enterItcDevChnName: null,
        carInTime: null,
        enterLaneCode: null,
        picPath: null,
        picData: null,
        monitorType: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      if(this.queryParams.carInTime){
        this.queryParams.carInTime = this.queryParams.carInTime + ' 00:00:00';
      }
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCarInTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 查看按钮操作 */
    handlePreview(row) {
      this.reset();
      const id = row.id || this.ids
      getRecordIn(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "车辆进场记录";
      });
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加车辆进场记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRecordIn(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改车辆进场记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRecordIn(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRecordIn(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除车辆进场记录编号为"' + ids + '"的数据项？').then(function() {
        return delRecordIn(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('parking/recordIn/export', {
        ...this.queryParams
      }, `recordIn_${new Date().getTime()}.xlsx`)
    },
    /** 远程开闸操作 */
    handleOpenGate(row) {
      this.$modal.confirm('是否确认为 '+row.carNum+' 远程开闸？').then(function() {
        return openGate(row.id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("远程开闸成功");
      }).catch(() => {});
    },
  }
};
</script>
